<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @classname Sub Categories
 *
 * @package	Package Name
 * @subpackage	Subpackage
 * @category	Category
 * @author	Ones Lynxs / 
 * @email ones006@gmail.com
 * @link	http://oemahcode.com
 * created 
 */

if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);

class Sub_categories extends OC_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('products/sub_category_model','scm');
		$this->load->model('products/category_model','cm');
		$this->upload_path = OC_FRONT_DIR . 'ocimages' . DS . 'subcatproducts' . DS;
	}

	function _remap($method, $params = array())
	{
		parent::_remap($method, $params);
		
		if (method_exists($this, $method))
			return call_user_func_array(array($this, $method), $params);
		else
			show_404();
	}

	function init_header()
	{
		$this->header['jeasyui'] = TRUE;
		$this->header['source_bot'] = array(
			script_tag(site_url('products/themescript/app/sub_product_category.js'))
		);
	}

	function index()
	{
		$this->init_header();
		$this->header['nav'] 			= 'products';
		$this->header['categories'] 	= $this->cm->get_all()->rows;
		$this->header['pagetitle'] 		= 'Product Sub Categories';
		
		$this->view('products/sub_categories_view');
	}

	function load_data()
	{
		$params = $this->input->post();
		$result = $this->scm->get_all($params);
		print(json_encode($result));
	}

	function save_data()
	{
		$post = $this->input->post();
		
		if (isset($_FILES['userfile']) && !empty($_FILES['userfile']['name'])) {
			$this->load->library('upload', array(
				'upload_path' => $this->upload_path,
				'allowed_types' => 'jpg|gif|png|bmp|JPG|GIF|PNG|BMP',
				'encrypt_name' => true
			));
			
			if ($this->upload->do_upload()) {
				$uploaded = $this->upload->data();
				$post['scp_filename'] = $uploaded['file_name'];
				$post['scp_origname'] = $uploaded['orig_name'];
			}

		}

		if (empty($post['scp_id']))
		{
			$post['scp_created_date']  = date('Y-m-d H:i:s');
			unset($post['scp_id']);
			$this->scm->add($post);
		}
		else
		{
			$post['scp_modified_date']  = date('Y-m-d H:i:s');
			$this->scm->edit($post, array('scp_id' => $post['scp_id']));
		}

		print(json_encode(array(
			'success' => TRUE
		)));
	}

	function delete_data()
	{
		$post = $this->input->post();
		$this->scm->delete(array('scp_id' => $post['scp_id']));
		print(json_encode(array(
			'success' => TRUE
		)));
	}

}

/* End of file categories.php */
/* Location: ./applications/module_admin/products/controllers/sub_categories.php */